package android.slc.appbase.ui.utils;


import android.slc.appbase.entity.DateSource;

import com.blankj.utilcode.util.TimeUtils;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public class DateSelectSourceUtils {
    private static String askForLeaveTimePattern = "yyyy年MM月dd日";

    public static List<DateSource> getDateSourceUp(int day) {
        List<DateSource> askForLeaveList = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        for (int i = 0; i < day; i++) {
            DateSource dateSource = new DateSource();
            dateSource.setTimeMillisecond(calendar.getTimeInMillis());
            dateSource.setDate(TimeUtils.millis2String(calendar.getTimeInMillis(), askForLeaveTimePattern));
            askForLeaveList.add(dateSource);
            calendar.add(Calendar.DATE, 1);
        }
        return askForLeaveList;
    }

    public static List<DateSource> getDateSourceDown(int day) {
        List<DateSource> askForLeaveList = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        for (int i = day; i >= 0; i--) {
            DateSource dateSource = new DateSource();
            dateSource.setTimeMillisecond(calendar.getTimeInMillis());
            dateSource.setDate(TimeUtils.millis2String(calendar.getTimeInMillis(), askForLeaveTimePattern));
            askForLeaveList.add(dateSource);
            calendar.add(Calendar.DATE, -1);
        }
        return askForLeaveList;
    }
}
